﻿using AntMovement.Core.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AntMovement.PCI1230.Domain
{
    public class HardwareUpdateDO : AntMovement.Core.IHardwareUpdate
    {
        private List<DO> _values = new List<DO>();
        private int _nCardNo;

        public HardwareUpdateDO(int nCardNo, DO[] values)
        {
            _nCardNo = nCardNo;
            _values.AddRange(values);
        }

        public string Update()
        {
            uint data = 0;
            int i = 0;
            long error = CPcie1230.Pci1230ReadDoBit(_nCardNo, i, ref data);
            if (error != 1024) { return $"Pci1230Read ==>> {(PCI1230Error)error}"; }
            _values[i].Status = data == 1;
            i = 1;
            error = CPcie1230.Pci1230ReadDoBit(_nCardNo, i, ref data);
            if (error != 1024) { return $"Pci1230Read ==>> {(PCI1230Error)error}"; }
            _values[i].Status = data == 1;
            i = 2;
            error = CPcie1230.Pci1230ReadDoBit(_nCardNo, i, ref data);
            if (error != 1024) { return $"Pci1230Read ==>> {(PCI1230Error)error}"; }
            _values[i].Status = data == 1;
            i = 3;
            error = CPcie1230.Pci1230ReadDoBit(_nCardNo, i, ref data);
            if (error != 1024) { return $"Pci1230Read ==>> {(PCI1230Error)error}"; }
            _values[i].Status = data == 1;
            i = 4;
            error = CPcie1230.Pci1230ReadDoBit(_nCardNo, i, ref data);
            if (error != 1024) { return $"Pci1230Read ==>> {(PCI1230Error)error}"; }
            _values[i].Status = data == 1;
            i = 5;
            error = CPcie1230.Pci1230ReadDoBit(_nCardNo, i, ref data);
            if (error != 1024) { return $"Pci1230Read ==>> {(PCI1230Error)error}"; }
            _values[i].Status = data == 1;
            i = 6;
            error = CPcie1230.Pci1230ReadDoBit(_nCardNo, i, ref data);
            if (error != 1024) { return $"Pci1230Read ==>> {(PCI1230Error)error}"; }
            _values[i].Status = data == 1;
            i = 7;
            error = CPcie1230.Pci1230ReadDoBit(_nCardNo, i, ref data);
            if (error != 1024) { return $"Pci1230Read ==>> {(PCI1230Error)error}"; }
            _values[i].Status = data == 1;
            i = 8;
            error = CPcie1230.Pci1230ReadDoBit(_nCardNo, i, ref data);
            if (error != 1024) { return $"Pci1230Read ==>> {(PCI1230Error)error}"; }
            _values[i].Status = data == 1;
            i = 9;
            error = CPcie1230.Pci1230ReadDoBit(_nCardNo, i, ref data);
            if (error != 1024) { return $"Pci1230Read ==>> {(PCI1230Error)error}"; }
            _values[i].Status = data == 1;
            i = 10;
            error = CPcie1230.Pci1230ReadDoBit(_nCardNo, i, ref data);
            if (error != 1024) { return $"Pci1230Read ==>> {(PCI1230Error)error}"; }
            _values[i].Status = data == 1;
            i = 11;
            error = CPcie1230.Pci1230ReadDoBit(_nCardNo, i, ref data);
            if (error != 1024) { return $"Pci1230Read ==>> {(PCI1230Error)error}"; }
            _values[i].Status = data == 1;
            i = 12;
            error = CPcie1230.Pci1230ReadDoBit(_nCardNo, i, ref data);
            if (error != 1024) { return $"Pci1230Read ==>> {(PCI1230Error)error}"; }
            _values[i].Status = data == 1;
            i = 13;
            error = CPcie1230.Pci1230ReadDoBit(_nCardNo, i, ref data);
            if (error != 1024) { return $"Pci1230Read ==>> {(PCI1230Error)error}"; }
            _values[i].Status = data == 1;
            i = 14;
            error = CPcie1230.Pci1230ReadDoBit(_nCardNo, i, ref data);
            if (error != 1024) { return $"Pci1230Read ==>> {(PCI1230Error)error}"; }
            _values[i].Status = data == 1;
            i = 15;
            error = CPcie1230.Pci1230ReadDoBit(_nCardNo, i, ref data);
            if (error != 1024) { return $"Pci1230Read ==>> {(PCI1230Error)error}"; }
            _values[i].Status = data == 1;
            if (_values.Count > 16)
            {
                i = 16;
                error = CPcie1230.Pci1230ReadDoBit(_nCardNo, i, ref data);
                if (error != 1024) { return $"Pci1230Read ==>> {(PCI1230Error)error}"; }
                _values[i].Status = data == 1;
                i = 17;
                error = CPcie1230.Pci1230ReadDoBit(_nCardNo, i, ref data);
                if (error != 1024) { return $"Pci1230Read ==>> {(PCI1230Error)error}"; }
                _values[i].Status = data == 1;
                i = 18;
                error = CPcie1230.Pci1230ReadDoBit(_nCardNo, i, ref data);
                if (error != 1024) { return $"Pci1230Read ==>> {(PCI1230Error)error}"; }
                _values[i].Status = data == 1;
                i = 19;
                error = CPcie1230.Pci1230ReadDoBit(_nCardNo, i, ref data);
                if (error != 1024) { return $"Pci1230Read ==>> {(PCI1230Error)error}"; }
                _values[i].Status = data == 1;
                i = 20;
                error = CPcie1230.Pci1230ReadDoBit(_nCardNo, i, ref data);
                if (error != 1024) { return $"Pci1230Read ==>> {(PCI1230Error)error}"; }
                _values[i].Status = data == 1;
                i = 21;
                error = CPcie1230.Pci1230ReadDoBit(_nCardNo, i, ref data);
                if (error != 1024) { return $"Pci1230Read ==>> {(PCI1230Error)error}"; }
                _values[i].Status = data == 1;
                i = 22;
                error = CPcie1230.Pci1230ReadDoBit(_nCardNo, i, ref data);
                if (error != 1024) { return $"Pci1230Read ==>> {(PCI1230Error)error}"; }
                _values[i].Status = data == 1;
                i = 23;
                error = CPcie1230.Pci1230ReadDoBit(_nCardNo, i, ref data);
                if (error != 1024) { return $"Pci1230Read ==>> {(PCI1230Error)error}"; }
                _values[i].Status = data == 1;
                i = 24;
                error = CPcie1230.Pci1230ReadDoBit(_nCardNo, i, ref data);
                if (error != 1024) { return $"Pci1230Read ==>> {(PCI1230Error)error}"; }
                _values[i].Status = data == 1;
                i = 25;
                error = CPcie1230.Pci1230ReadDoBit(_nCardNo, i, ref data);
                if (error != 1024) { return $"Pci1230Read ==>> {(PCI1230Error)error}"; }
                _values[i].Status = data == 1;
                i = 26;
                error = CPcie1230.Pci1230ReadDoBit(_nCardNo, i, ref data);
                if (error != 1024) { return $"Pci1230Read ==>> {(PCI1230Error)error}"; }
                _values[i].Status = data == 1;
                i = 27;
                error = CPcie1230.Pci1230ReadDoBit(_nCardNo, i, ref data);
                if (error != 1024) { return $"Pci1230Read ==>> {(PCI1230Error)error}"; }
                _values[i].Status = data == 1;
                i = 28;
                error = CPcie1230.Pci1230ReadDoBit(_nCardNo, i, ref data);
                if (error != 1024) { return $"Pci1230Read ==>> {(PCI1230Error)error}"; }
                _values[i].Status = data == 1;
                i = 29;
                error = CPcie1230.Pci1230ReadDoBit(_nCardNo, i, ref data);
                if (error != 1024) { return $"Pci1230Read ==>> {(PCI1230Error)error}"; }
                _values[i].Status = data == 1;
                i = 30;
                error = CPcie1230.Pci1230ReadDoBit(_nCardNo, i, ref data);
                if (error != 1024) { return $"Pci1230Read ==>> {(PCI1230Error)error}"; }
                _values[i].Status = data == 1;
                i = 31;
                error = CPcie1230.Pci1230ReadDoBit(_nCardNo, i, ref data);
                if (error != 1024) { return $"Pci1230Read ==>> {(PCI1230Error)error}"; }
                _values[i].Status = data == 1;
            }
            return "ok";
        }
    }
}
